<?php

use yii\db\Migration;

/**
 * Handles adding columns to table `{{%project}}`.
 * Has foreign keys to the tables:
 *
 * - `{{%user}}`
 * - `{{%user}}`
 */
class m230131_083709_add_new_column_to_project_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->addColumn('{{%project}}', 'id_accountant', $this->integer());
        $this->addColumn('{{%project}}', 'id_curator', $this->integer());
        $this->addColumn('{{%project}}', 'url_work_budget', $this->string(512));

        // creates index for column `id_accountant`
        $this->createIndex(
            '{{%idx-project-id_accountant}}',
            '{{%project}}',
            'id_accountant'
        );

        // add foreign key for table `{{%user}}`
        $this->addForeignKey(
            '{{%fk-project-id_accountant}}',
            '{{%project}}',
            'id_accountant',
            '{{%user}}',
            'id',
            'CASCADE'
        );

        // creates index for column `id_curator`
        $this->createIndex(
            '{{%idx-project-id_curator}}',
            '{{%project}}',
            'id_curator'
        );

        // add foreign key for table `{{%user}}`
        $this->addForeignKey(
            '{{%fk-project-id_curator}}',
            '{{%project}}',
            'id_curator',
            '{{%user}}',
            'id',
            'CASCADE'
        );
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        // drops foreign key for table `{{%user}}`
        $this->dropForeignKey(
            '{{%fk-project-id_accountant}}',
            '{{%project}}'
        );

        // drops index for column `id_accountant`
        $this->dropIndex(
            '{{%idx-project-id_accountant}}',
            '{{%project}}'
        );

        // drops foreign key for table `{{%user}}`
        $this->dropForeignKey(
            '{{%fk-project-id_curator}}',
            '{{%project}}'
        );

        // drops index for column `id_curator`
        $this->dropIndex(
            '{{%idx-project-id_curator}}',
            '{{%project}}'
        );

        $this->dropColumn('{{%project}}', 'id_accountant');
        $this->dropColumn('{{%project}}', 'id_curator');
        $this->dropColumn('{{%project}}', 'url_work_budget');
    }
}
